/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package base;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author tacio
 */
public class TorrentDownload implements Runnable {

    private URL url;

    public TorrentDownload(URL url){
        this.url = url;
    }

    public void run() {

        String file = url.getFile();

        java.io.BufferedInputStream in;
        try {
            in = new java.io.BufferedInputStream(url.openStream());
            java.io.FileOutputStream fos = new java.io.FileOutputStream("/home/tacio/Download" + file);
            java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
            byte data[] = new byte[1024];
            int x = 0;
            while ((x = in.read(data, 0, 1024)) >= 0) {
                bout.write(data, 0, x);
            }
            bout.close();
            in.close();
        } catch (IOException ex) {
            Logger.getLogger(TorrentDownload.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
